<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>商品详情</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no">
    <meta name="renderer" content="webkit" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="renderer" content="webkit|ie-comp|ie-stand" />
    <link rel="shortcut icon" href="/favicon.ico" type="/image/x-icon">
    <link rel="apple-touch-icon-precomposed" href="">
    <link rel="stylesheet" href="../source/src/css/main.css"/>
    
</head>
<body class="shop-detail-body">
<div class="shop-deatil" id="shop-deatil">

</div>

<!--底部菜单-->
<div class="pub-nav">
    <ul>
        <li>
            <a href="../index.html">
                <div class="index pic"></div>
                <div class="txt">首页</div>
            </a>
        </li>
        <li>
            <a href="shop_cart.html">
                <div class="shopCart pic"><!--<i class="num" id="shop-cart-num">0</i>--></div>
                <div class="txt">购物车</div>
            </a>
        </li>
        <li>
            <a href="./me.html">
                <div class="me pic"></div>
                <div class="txt">我</div>
            </a>
        </li>
    </ul>
</div>
<!--/底部菜单-->

<script id="shop-deatil-tpl" type="text/html">
    <!-- 轮播图片 -->
    <div id="yx_slider" class="yx_slider">
        <ul class="clearfix" >
            <li class="item">
                <img src="{{ItemList[0].Picture}}" alt="">
            </li>
        </ul>
        <ul class="slide-trigger">
            <!--<li class="on"></li>
            <li class=""></li>-->
        </ul>
    </div>
    <!-- /轮播图片 -->

    <!--简述-->
    <div class="intro clearfix">
        <h1 class="fl">{{ItemList[0].Name}}</h1>
        <div class="other cleerfix fl">
            <span class="model fl">{{ItemList[0].HelpCode}}</span>
            <span class="type fl">{{ItemList[0].GMPDoseKind}}</span>
        </div>
    </div>

    <!--详细内容-->
    <div class="detail-box">
        <div class="cont">
            <h3>详情：</h3>
            <ul class="clearfix">
                <li>
                    存储条件：{{ItemList[0].Store}}
                </li>
                <li>
                    备注：{{ItemList[0].Remark}}
                </li>
            </ul>
        </div>
    </div>
    <!--/详细内容-->
    <div class="btn-box">
        <!--数量-->
        <div class="change-num clearfix fl">
            <div class="num_wrap clearfix fl" >
                <i id="minus" class="minus minus_disabled fl"></i>
                <input type="tel" value="1" id="buyNum" class="num fl">
                <i id="plus" class="plus fl"></i>
            </div>
        </div>
        <!--/数量-->

        <div class="fr">
            <a href="javascript:;" class="add-to-shopCart" id="add-to-shopCart">加入购物车</a>
        </div>
    </div>
</script>

<script src="../source/plugin/zepto.min.js"></script>
<script src="../source/plugin/artTemplate.js"></script>
<!--<script src="../source/plugin/swipe-2.0.min.js"></script>-->
<script src="../source/src/js/common.js"></script>
<script>
    $(function(){
//            slider('yx_slider');
        var init = {
            submitFlag:true,
            render:function(){
                 var inJson = {
                    "number":getQueryString('number'),
                    "name":"",
                    "key":user.key,
                    "account":user.account
                };

                $.ajax({
                    url:apiUrl+'/GetProdItemsByOne',
                    type:'GET',
                    data:{"json":JSON.stringify(inJson)},
                    //dataType :'jsonp',
                    success:function(datas){
                        console.log(datas);
                        var html = template('shop-deatil-tpl', datas);
                        $('#shop-deatil').html(html);

                    },
                    error:function(datas){
                        console.log(datas.msg)
                    }
                });
            },
            addNum:function(){
                $('#shop-deatil').on('tap','.plus',function(){
                    var $this = $(this);
                    var numObj = $this.siblings('.num');
                    var numVal = numObj.val()*1;
                    numVal++;
                    if(numVal>1){
                        $this.siblings('.minus').removeClass('minus_disabled');
                    }
                   /* if(numVal>=100){
                        numVal=100;
                    }*/
                    numObj.val(numVal);
                });
            },
            reduceNum:function(){
                $('#shop-deatil').on('tap','.minus',function(){
                    var $this = $(this);
                    var numObj = $this.siblings('.num');
                    var numVal = numObj.val()*1;
                    numVal--;
                    if(numVal<=1){
                        numVal=1;
                        $this.addClass('minus_disabled');
                    }
                    numObj.val(numVal);
                });
            },
            addToCart:function(){ //todo
                //加入购物车
                var _this=this;
                $('#shop-deatil').on('click','#add-to-shopCart',function(){
                    _this.submitFlag=false;
                    var inJson = {
                        "OrderLists": [
                            {
                                "ItemList": [
                                    {
                                        "Code":getQueryString('number'),
                                        "Name": "",
                                        "Model": null,
                                        "Picture": "",
                                        "Qty": $('#buyNum').val(),
                                        "Price":0,
                                        "Total":0
                                    }
                                ],
                                "CustNo":getCookie('CustCode'),
                                "EmpNo":getCookie('EmpCode'),
                                "UserName":decodeURIComponent(getCookie('username')),
                                "key":user.key,
                                "account":user.account
                            }
                        ]
                    };

                    if(!_this.submitFlag){
                        $.ajax({
                            url:apiUrl+'/SubmitCarItems',
                            type:'GET',
                            data:{"json":JSON.stringify(inJson)},
                            //          dataType :'jsonp',
                            success:function(datas){
                                if(datas.Success==true){
                                    show_error_tip({str:'加入购物车成功'});
                                    _this.submitFlag = true;
                                }
                            },
                            error:function(datas){
                                console.log(datas.msg)
                                _this.submitFlag = true;
                            }
                        });
                    }
                });
            },
            init:function(){
                this.render();
                this.addToCart();
                this.addNum();
                this.reduceNum();
            }
        };

        init.init();

    })
</script>
</body>
</html>